#pragma GCC optimize(2)
#pragma GCC optimize(3)

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 2e6;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n, a[N];
int last[40], L[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    LL ans = 0;
    L[0] = 1;
    for (int i = 1; i <= n; i++)cin >> a[i];
    for (int i = 1; i <= n; i++) {
        int pre = L[i - 1];
        for (int j = 0; j <= 30; j++) {
            if (1ll << j & a[i]) {
                pre = max(pre, last[j] + 1);
                last[j] = i;
            }
        }
        L[i] = max(L[i - 1], pre);
        ans += i - pre + 1;
    }
    cout << ans << '\n';
    return 0;
}
